<template>
    <div>
      <h3> 用户登录 </h3>
      <p>用户名:<input type="text" v-model="name"></p>
      <p>密码:<input type="text" v-model="password"></p>
      <p><button @click="btn">登录</button></p>
    </div>
</template>

<script>
    export default {
        data(){
          return{
            name:'',
            password:'',
          }
        },
        methods:{
          btn(){
            let form_data=new FormData()
            form_data.append('name',this.username)
            form_data.append('password',this.password)
            axios({
              url:'http://127.0.0.1:8000/app02/login/',
              method:'post',
              data:form_data
            }).then(res=>{
              console.log(res)
              if(res.data.code==1000){
                sessionStorage.setItem('user_id',res.data.user_id)
                sessionStorage.setItem('user',res.data.user)
                this.$router.push({
                    name:Product
                })
              }
            })
          }
        }
    }
</script>

<style scoped>

</style>